﻿using Microsoft.Practices.Unity;
using XamlaApp.Views;
using XamlaApp.Views.ElementViews;
using XamlaApp.Views.ElementPropertyViews;
using XamlaApp.ViewModels;
using XamlaApp.Views.ElementMenuButtonViews;
using XamlaApp.Views.UIViews;
using XamlaApp.Interfaces;
using XamlaApp.Model;

namespace XamlaApp{
    public static class Container
    {
        public static UnityContainer AppContainer
        {
            get;
            private set;
        }

        static Container()
        {
            InitContainer();
        }

        public static void InitContainer()
        {
            AppContainer = new UnityContainer();

            //register main runtime types
            AppContainer.RegisterType<XamlaModel>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<Stage>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<XamlaMainPage>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<MainUIViewModel>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<EmptyPropertiesView>(new ContainerControlledLifetimeManager());

            //register the element views with unique names to they can be queried with .ResolveAll<IXamalaElement>
            AppContainer.RegisterType<IXamlaElement, TextBlockView>("TextBlock");
            AppContainer.RegisterType<IXamlaElement, EllipseView>("Ellipse");
            AppContainer.RegisterType<IXamlaElement, RectangleView>("Rectangle");
            AppContainer.RegisterType<IXamlaElement, BorderView>("Border");
            AppContainer.RegisterType<IXamlaElement, ImageView>("Image");

            //register view models
            AppContainer.RegisterType<ElementMenuButtonViewModel>();
            AppContainer.RegisterType<TextBlockViewModel>();
            AppContainer.RegisterType<EllipseViewModel>();
            AppContainer.RegisterType<RectangleViewModel>();
            AppContainer.RegisterType<BorderViewModel>();
            AppContainer.RegisterType<ShapeViewModel>();
            AppContainer.RegisterType<ImageViewModel>();

            //element property views
            AppContainer.RegisterType<TextBlockProperties>();
            AppContainer.RegisterType<EllipseProperties>();
            AppContainer.RegisterType<RectangleProperties>();
            AppContainer.RegisterType<BorderProperties>();
            AppContainer.RegisterType<ImagePropertyView>();

            //menu button content
            AppContainer.RegisterType<BorderMenuButtonContent>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<EllipseMenuButton>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<RectangleMenuButtonContent>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<TextBlockMenuButton>(new ContainerControlledLifetimeManager());
            AppContainer.RegisterType<ImageMenuButton>(new ContainerControlledLifetimeManager());
        }
    }
}
